import marketingApi from '@/config/server/api/marketing.js'
import userApi from '@/config/server/api/user.js'
import baseApi from '@/config/server/api/base'
import dt from '@dt/dt'

//推广活动列表
function list(params) {
  return marketingApi.customerForCode.list.fetch(params).then((res) => {
    return res
  })
}
//新增推广活动
function create(params) {
  return marketingApi.customerForCode.create.fetch(params).then((res) => {
    return res
  })
}
//删除推广活动
function del(params) {
  return marketingApi.customerForCode.del.fetch(params).then((res) => {
    return res
  })
}
//下载推广码
function downloadPromoteCodeNew(params) {
  return marketingApi.customerForCode.downloadPromoteCodeNew.fetch(params).then((res) => {
    return res
  })
}
//推广活动详情
function detail(params) {
  return marketingApi.customerForCode.detail.fetch(params).then((res) => {
    return res
  })
}
//更新推广活动
function update(params) {
  return marketingApi.customerForCode.update.fetch(params).then((res) => {
    return res
  })
}
//获取活动所有推广码
function listPromoteCode(params) {
  return marketingApi.customerForCode.listPromoteCode.fetch(params).then((res) => {
    return res
  })
}

//案场人员列表在案顾问
function adviserList() {
  return userApi.customer.adviserList
    .fetch({
      buildingId: dt.buildInfo().housesId,
      onlineType: 1,
      haveRole: 1
    })
    .then((res) => {
      return res
    })
}

//推广活动详情统计
function count(params) {
  return marketingApi.customerForCode.count.fetch(params).then((res) => {
    return res
  })
}

//推广活动详情-导出
function detailExport(params) {
  return marketingApi.customerForCode.detailExport.fetch(params).then((res) => {
    return res
  })
}

//推广活动列表-导出
function listExport(params) {
  return marketingApi.customerForCode.listExport.fetch(params).then((res) => {
    return res
  })
}

function getAppropriateByBuildingId(params) {
  return baseApi.caseChannel.caseChannelTreeList.fetch(params).then((res) => {
    let data = []
    data =
      res &&
      res.map((i) => ({
        key: i.channelId,
        value: i.channelName
      }))
    return data
  })
}
export default {
  list,
  create,
  del,
  downloadPromoteCodeNew,
  detail,
  update,
  listPromoteCode,
  adviserList,
  count,
  detailExport,
  listExport,
  getAppropriateByBuildingId
}
